
const fs = require('fs')

const path = require('path')

const fileList = []

/** 
* 获取js文件 
* @param {string} rootPath 根路径
* @param {string} filePath 需要查找的路径
 * @return {list} fileList 返回的文件的完整路径
*/
const dir = (rootPath,filePath) => {
    const filterJS = /js$/
    const file = fs.readdirSync(path.resolve(rootPath,filePath))
    file.forEach(item => {
        if(filterJS.test(item)){
            const file = path.resolve(rootPath, filePath, item)
            fileList.push(file)
        } else {
            dir(rootPath, `${filePath}/${item}`)
        }
    })
}



module.exports = {
    read_dir: dir,
    fileList
}